package com.github.appintro;

import ohos.agp.colors.RgbColor;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;

public abstract class AppIntro extends AppIntroBase {
    public void setLayoutId() {
        layoutId = ResourceTable.Layout_appintro_intro_layout;
    }

    /**
     * Override viewpager bar color
     *
     * @param color your color resource
     */
    void setBarColor(int color) {
        Component bottomBar = findComponentById(ResourceTable.Id_bottom);
        ShapeElement shapeElement = new ShapeElement();
        RgbColor rgbColor = new RgbColor(color);
        shapeElement.setRgbColor(rgbColor);
        bottomBar.setBackground(shapeElement);
    }

    void setNextArrowColor(int color) {
        Image nextButton = (Image) findComponentById(ResourceTable.Id_next);
        ShapeElement shapeElement = new ShapeElement();
        shapeElement.setRgbColor(new RgbColor(color));
        nextButton.setBackground(shapeElement);
    }

    void setBackArrowColor(int color) {
        Image backButton = (Image) findComponentById(ResourceTable.Id_back);
        ShapeElement shapeElement = new ShapeElement();
        shapeElement.setRgbColor(new RgbColor(color));
        backButton.setBackground(shapeElement);
    }

    /**
     * Override separator color
     *
     * @param color your color resource
     */
    void setSeparatorColor(int color) {
        Component separator = findComponentById(ResourceTable.Id_bottom_separator);
        ShapeElement shapeElement = new ShapeElement();
        RgbColor rgbColor = new RgbColor(color);
        shapeElement.setRgbColor(rgbColor);
        separator.setBackground(shapeElement);
    }

    /**
     * Override skip text
     *
     * @param text your text
     */
    void setSkipText(CharSequence text) {
        Text skipText = (Text) findComponentById(ResourceTable.Id_skip);
        skipText.setText(text.toString());
    }

    /**
     * Override skip text
     *
     * @param skipResId your text resource Id
     */
    void setSkipText(int skipResId) {
        Text skipText = (Text) findComponentById(ResourceTable.Id_skip);
        skipText.setText(skipResId);
    }

    /**
     * Override done text
     *
     * @param text your text
     */
    void setDoneText(CharSequence text) {
        Text doneText = (Text) findComponentById(ResourceTable.Id_done);
        doneText.setText(text.toString());
    }

    /**
     * Override done text
     *
     * @param doneResId your text resource Id
     */
    void setDoneText(int doneResId) {
        Text doneText = (Text) findComponentById(ResourceTable.Id_done);
        doneText.setText(doneResId);
    }

    /**
     * Override done button text color
     *
     * @param colorDoneText your color resource
     */
    void setColorDoneText(int colorDoneText) {
        Text doneText = (Text) findComponentById(ResourceTable.Id_done);
        doneText.setTextColor(new Color(colorDoneText));
    }

    /**
     * Override done button text overall style
     *
     * @param textAppearance your text style from resource
     */
    void setDoneTextAppearance(int textAppearance) {
        Text doneText = (Text) findComponentById(ResourceTable.Id_done);
        doneText.setTextAlignment(textAppearance);
    }

    /**
     * Override skip button color
     *
     * @param colorSkipButton your color resource
     */
    void setColorSkipButton(int colorSkipButton) {
        Text skip = (Text) findComponentById(ResourceTable.Id_skip);
        skip.setTextColor(new Color(colorSkipButton));
    }

    /**
     * Override skip button text overall style
     *
     * @param textAppearance your text style from resource
     */
    void setSkipTextAppearance(int textAppearance) {
        Text skip = (Text) findComponentById(ResourceTable.Id_skip);
        skip.setTextAlignment(textAppearance);
    }

    /**
     * Override Next button
     *
     * @param imageNextButton your drawable resource
     */
    void setImageNextButton(Element imageNextButton) {
        Image nextButton = (Image) findComponentById(ResourceTable.Id_next);
        nextButton.setImageElement(imageNextButton);
    }

    /**
     * Show or hide the Separator line.
     * This is a static setting and Separator state is maintained across slides
     * until explicitly changed.
     *
     * @param showSeparator Set : true to display. false to hide.
     */
    void showSeparator(boolean showSeparator) {
        Component bottomSeparator = findComponentById(ResourceTable.Id_bottom_separator);
        if (showSeparator) {
            bottomSeparator.setVisibility(Component.VISIBLE);
        } else {
            bottomSeparator.setVisibility(Component.INVISIBLE);
        }
    }
}
